
# Violência e legitimidade democrática na América Latina:
# mecanismos causais e efeitos contextuais em perspectiva

# Gabriela Ribeiro Cardoso

# Diretório:

setwd("/Users/felipe/Desktop/dados_replicacao")

# Pacotes:

if(require(haven)==F){install.packages("haven");require(haven)}
if(require(labelled)==F){install.packages("labelled");require(labelled)}
if(require(sjPlot)==F){install.packages("sjPlot");require(sjPlot)}
if(require(multilevel)==F){install.packages("multilevel");require(multilevel)}
if(require(stargazer)==F){install.packages("stargazer");require(stargazer)}
if(require(Hmisc)==F){install.packages("Hmisc");require(Hmisc)}
if(require(expss)==F){install.packages("expss");require(expss)}
if(require(car)==F){install.packages("car");require(car)}
if(require(coefplot)==F){install.packages("coefplot");require(coefplot)}
if(require(readxl)==F){install.packages("readxl");require(readxl)}
if(require(png)==F){install.packages("png");require(png)}

#############################################################################
############ OPERACIONALIZAÇÃO BANCO DE DADOS  ##############################
#############################################################################

########### NÍVEL 1 #########################################################

# Argentina 2016
Argentina16 <- read_dta("Argentina_16.dta")

val_labels(Argentina16$pais) <- NULL
val_labels(Argentina16$wt) <- NULL
val_labels(Argentina16$ur) <- NULL
val_labels(Argentina16$a4) <- NULL

#Variáveis dependentes
val_labels(Argentina16$b1) <- NULL
val_labels(Argentina16$b2) <- NULL
val_labels(Argentina16$b3) <- NULL 
val_labels(Argentina16$b4) <- NULL 
val_labels(Argentina16$b6) <- NULL 
val_labels(Argentina16$b13) <- NULL
val_labels(Argentina16$b18) <- NULL
val_labels(Argentina16$b21) <- NULL
val_labels(Argentina16$b21a) <- NULL
val_labels(Argentina16$b32) <- NULL
val_labels(Argentina16$b37) <- NULL
val_labels(Argentina16$b47a) <- NULL
val_labels(Argentina16$ing4) <- NULL
val_labels(Argentina16$pn4) <- NULL

#Variáveis independentes
val_labels(Argentina16$vic1ext) <- NULL
val_labels(Argentina16$aoj11) <- NULL
val_labels(Argentina16$it1) <- NULL
val_labels(Argentina16$jc10) <- NULL
val_labels(Argentina16$jc13) <- NULL
val_labels(Argentina16$q1) <- NULL
val_labels(Argentina16$q2) <- NULL
val_labels(Argentina16$ed) <- NULL
val_labels(Argentina16$q10new) <- NULL
val_labels(Argentina16$etid) <- NULL
val_labels(Argentina16$soct2) <- NULL
val_labels(Argentina16$idio2) <- NULL
val_labels(Argentina16$infrax) <- NULL
val_labels(Argentina16$exc14) <- NULL
val_labels(Argentina16$cp8) <- NULL
val_labels(Argentina16$prot3) <- NULL
val_labels(Argentina16$vb2) <- NULL

save(Argentina16, file="ARG16.RData")

#Argentina 2018
Argentina18 <- read_dta("Argentina_18.dta")

val_labels(Argentina18$pais) <- NULL
val_labels(Argentina18$wt) <- NULL
val_labels(Argentina18$ur) <- NULL
val_labels(Argentina18$a4) <- NULL

#Variáveis dependentes
val_labels(Argentina18$b1) <- NULL
val_labels(Argentina18$b2) <- NULL
val_labels(Argentina18$b3) <- NULL 
val_labels(Argentina18$b4) <- NULL 
val_labels(Argentina18$b6) <- NULL 
val_labels(Argentina18$b13) <- NULL
val_labels(Argentina18$b18) <- NULL
val_labels(Argentina18$b21) <- NULL
val_labels(Argentina18$b21a) <- NULL
val_labels(Argentina18$b32) <- NULL
val_labels(Argentina18$b37) <- NULL
val_labels(Argentina18$b47a) <- NULL
val_labels(Argentina18$ing4) <- NULL
val_labels(Argentina18$pn4) <- NULL

#Variáveis independentes
val_labels(Argentina18$vic1ext) <- NULL
val_labels(Argentina18$aoj11) <- NULL
val_labels(Argentina18$it1) <- NULL
val_labels(Argentina18$jc10) <- NULL
val_labels(Argentina18$jc13) <- NULL
val_labels(Argentina18$q1) <- NULL
val_labels(Argentina18$q2) <- NULL
val_labels(Argentina18$ed) <- NULL
val_labels(Argentina18$q10new) <- NULL
val_labels(Argentina18$etid) <- NULL
val_labels(Argentina18$soct2) <- NULL
val_labels(Argentina18$idio2) <- NULL
val_labels(Argentina18$infrax) <- NULL
val_labels(Argentina18$exc14) <- NULL
val_labels(Argentina18$cp8) <- NULL
val_labels(Argentina18$prot3) <- NULL
val_labels(Argentina18$vb2) <- NULL

save(Argentina18, file="ARG18.RData")

#Bolívia
Bolivia16 <- read_dta("Bolivia_16.dta")

val_labels(Bolivia16$pais) <- NULL
val_labels(Bolivia16$wt) <- NULL
val_labels(Bolivia16$ur) <- NULL
val_labels(Bolivia16$a4) <- NULL

#Variáveis dependentes
val_labels(Bolivia16$b1) <- NULL
val_labels(Bolivia16$b2) <- NULL
val_labels(Bolivia16$b3) <- NULL 
val_labels(Bolivia16$b4) <- NULL 
val_labels(Bolivia16$b6) <- NULL 
val_labels(Bolivia16$b13) <- NULL
val_labels(Bolivia16$b18) <- NULL
val_labels(Bolivia16$b21) <- NULL
val_labels(Bolivia16$b21a) <- NULL
val_labels(Bolivia16$b32) <- NULL
val_labels(Bolivia16$b37) <- NULL
val_labels(Bolivia16$b47a) <- NULL
val_labels(Bolivia16$ing4) <- NULL
val_labels(Bolivia16$pn4) <- NULL

#Variáveis independentes
val_labels(Bolivia16$vic1ext) <- NULL
val_labels(Bolivia16$aoj11) <- NULL
val_labels(Bolivia16$it1) <- NULL
val_labels(Bolivia16$jc10) <- NULL
val_labels(Bolivia16$jc13) <- NULL
val_labels(Bolivia16$q1) <- NULL
val_labels(Bolivia16$q2) <- NULL
val_labels(Bolivia16$ed) <- NULL
val_labels(Bolivia16$q10new) <- NULL
val_labels(Bolivia16$etid) <- NULL
val_labels(Bolivia16$soct2) <- NULL
val_labels(Bolivia16$idio2) <- NULL
val_labels(Bolivia16$infrax) <- NULL
val_labels(Bolivia16$exc14) <- NULL
val_labels(Bolivia16$cp8) <- NULL
val_labels(Bolivia16$prot3) <- NULL
val_labels(Bolivia16$vb2) <- NULL

save(Bolivia16, file="BOL16.RData")

#Bolívia 2018
Bolivia18 <- read_dta("Bolivia_18.dta")

val_labels(Bolivia18$pais) <- NULL
val_labels(Bolivia18$wt) <- NULL
val_labels(Bolivia18$ur) <- NULL
val_labels(Bolivia18$a4) <- NULL

#Variáveis dependentes
val_labels(Bolivia18$b1) <- NULL
val_labels(Bolivia18$b2) <- NULL
val_labels(Bolivia18$b3) <- NULL 
val_labels(Bolivia18$b4) <- NULL 
val_labels(Bolivia18$b6) <- NULL 
val_labels(Bolivia18$b13) <- NULL
val_labels(Bolivia18$b18) <- NULL
val_labels(Bolivia18$b21) <- NULL
val_labels(Bolivia18$b21a) <- NULL
val_labels(Bolivia18$b32) <- NULL
val_labels(Bolivia18$b37) <- NULL
val_labels(Bolivia18$b47a) <- NULL
val_labels(Bolivia18$ing4) <- NULL
val_labels(Bolivia18$pn4) <- NULL

#Variáveis independentes
val_labels(Bolivia18$vic1ext) <- NULL
val_labels(Bolivia18$aoj11) <- NULL
val_labels(Bolivia18$it1) <- NULL
val_labels(Bolivia18$jc10) <- NULL
val_labels(Bolivia18$jc13) <- NULL
val_labels(Bolivia18$q1) <- NULL
val_labels(Bolivia18$q2) <- NULL
val_labels(Bolivia18$ed) <- NULL
val_labels(Bolivia18$q10new) <- NULL
val_labels(Bolivia18$etid) <- NULL
val_labels(Bolivia18$soct2) <- NULL
val_labels(Bolivia18$idio2) <- NULL
val_labels(Bolivia18$infrax) <- NULL
val_labels(Bolivia18$exc14) <- NULL
val_labels(Bolivia18$cp8) <- NULL
val_labels(Bolivia18$prot3) <- NULL
val_labels(Bolivia18$vb2) <- NULL

save(Bolivia18, file="BOL18.RData")

#Brasil
Brasil16 <- read_dta("Brasil_16.dta")

val_labels(Brasil16$pais) <- NULL
val_labels(Brasil16$wt) <- NULL
val_labels(Brasil16$ur) <- NULL
val_labels(Brasil16$a4) <- NULL

#Variáveis dependentes
val_labels(Brasil16$b1) <- NULL
val_labels(Brasil16$b2) <- NULL
val_labels(Brasil16$b3) <- NULL 
val_labels(Brasil16$b4) <- NULL 
val_labels(Brasil16$b6) <- NULL 
val_labels(Brasil16$b13) <- NULL
val_labels(Brasil16$b18) <- NULL
val_labels(Brasil16$b21) <- NULL
val_labels(Brasil16$b21a) <- NULL
val_labels(Brasil16$b32) <- NULL
val_labels(Brasil16$b37) <- NULL
val_labels(Brasil16$b47a) <- NULL
val_labels(Brasil16$ing4) <- NULL
val_labels(Brasil16$pn4) <- NULL

#Variáveis independentes
val_labels(Brasil16$vic1ext) <- NULL
val_labels(Brasil16$aoj11) <- NULL
val_labels(Brasil16$it1) <- NULL
val_labels(Brasil16$jc10) <- NULL
val_labels(Brasil16$jc13) <- NULL
val_labels(Brasil16$q1) <- NULL
val_labels(Brasil16$q2) <- NULL
val_labels(Brasil16$ed) <- NULL
val_labels(Brasil16$q10new) <- NULL
val_labels(Brasil16$etid) <- NULL
val_labels(Brasil16$soct2) <- NULL
val_labels(Brasil16$idio2) <- NULL
val_labels(Brasil16$infrax) <- NULL
val_labels(Brasil16$exc14) <- NULL
val_labels(Brasil16$cp8) <- NULL
val_labels(Brasil16$prot3) <- NULL
val_labels(Brasil16$vb2) <- NULL

save(Brasil16, file="BRA16.RData")

#Brasil 2018
Brasil18 <- read_dta("Brasil_18.dta")

val_labels(Brasil18$pais) <- NULL
val_labels(Brasil18$wt) <- NULL
val_labels(Brasil18$ur) <- NULL
val_labels(Brasil18$a4) <- NULL

#Variáveis dependentes
val_labels(Brasil18$b1) <- NULL
val_labels(Brasil18$b2) <- NULL
val_labels(Brasil18$b3) <- NULL 
val_labels(Brasil18$b4) <- NULL 
val_labels(Brasil18$b6) <- NULL 
val_labels(Brasil18$b13) <- NULL
val_labels(Brasil18$b18) <- NULL
val_labels(Brasil18$b21) <- NULL
val_labels(Brasil18$b21a) <- NULL
val_labels(Brasil18$b32) <- NULL
val_labels(Brasil18$b37) <- NULL
val_labels(Brasil18$b47a) <- NULL
val_labels(Brasil18$ing4) <- NULL
val_labels(Brasil18$pn4) <- NULL

#Variáveis independentes
val_labels(Brasil18$vic1ext) <- NULL
val_labels(Brasil18$aoj11) <- NULL
val_labels(Brasil18$it1) <- NULL
val_labels(Brasil18$jc10) <- NULL
val_labels(Brasil18$jc13) <- NULL
val_labels(Brasil18$q1) <- NULL
val_labels(Brasil18$q2) <- NULL
val_labels(Brasil18$ed) <- NULL
val_labels(Brasil18$q10new) <- NULL
val_labels(Brasil18$etid) <- NULL
val_labels(Brasil18$soct2) <- NULL
val_labels(Brasil18$idio2) <- NULL
val_labels(Brasil18$infrax) <- NULL
val_labels(Brasil18$exc14) <- NULL
val_labels(Brasil18$cp8) <- NULL
val_labels(Brasil18$prot3) <- NULL
val_labels(Brasil18$vb2) <- NULL

save(Brasil18, file="BRA18.RData")

#Chile
Chile16 <- read_dta("Chile_16.dta")

val_labels(Chile16$pais) <- NULL
val_labels(Chile16$wt) <- NULL
val_labels(Chile16$ur) <- NULL
val_labels(Chile16$a4) <- NULL

#Variáveis dependentes
val_labels(Chile16$b1) <- NULL
val_labels(Chile16$b2) <- NULL
val_labels(Chile16$b3) <- NULL 
val_labels(Chile16$b4) <- NULL 
val_labels(Chile16$b6) <- NULL 
val_labels(Chile16$b13) <- NULL
val_labels(Chile16$b18) <- NULL
val_labels(Chile16$b21) <- NULL
val_labels(Chile16$b21a) <- NULL
val_labels(Chile16$b32) <- NULL
val_labels(Chile16$b37) <- NULL
val_labels(Chile16$b47a) <- NULL
val_labels(Chile16$ing4) <- NULL
val_labels(Chile16$pn4) <- NULL

#Variáveis independentes
val_labels(Chile16$vic1ext) <- NULL
val_labels(Chile16$aoj11) <- NULL
val_labels(Chile16$it1) <- NULL
val_labels(Chile16$jc10) <- NULL
val_labels(Chile16$jc13) <- NULL
val_labels(Chile16$q1) <- NULL
val_labels(Chile16$q2) <- NULL
val_labels(Chile16$ed) <- NULL
val_labels(Chile16$q10new) <- NULL
val_labels(Chile16$etid) <- NULL
val_labels(Chile16$soct2) <- NULL
val_labels(Chile16$idio2) <- NULL
val_labels(Chile16$infrax) <- NULL
val_labels(Chile16$exc14) <- NULL
val_labels(Chile16$cp8) <- NULL
val_labels(Chile16$prot3) <- NULL
val_labels(Chile16$vb2) <- NULL

save(Chile16, file="CHI16.RData")

#Chile 2018
Chile18 <- read_dta("Chile_18.dta")

val_labels(Chile18$pais) <- NULL
val_labels(Chile18$wt) <- NULL
val_labels(Chile18$ur) <- NULL
val_labels(Chile18$a4) <- NULL

#Variáveis dependentes
val_labels(Chile18$b1) <- NULL
val_labels(Chile18$b2) <- NULL
val_labels(Chile18$b3) <- NULL 
val_labels(Chile18$b4) <- NULL 
val_labels(Chile18$b6) <- NULL 
val_labels(Chile18$b13) <- NULL
val_labels(Chile18$b18) <- NULL
val_labels(Chile18$b21) <- NULL
val_labels(Chile18$b21a) <- NULL
val_labels(Chile18$b32) <- NULL
val_labels(Chile18$b37) <- NULL
val_labels(Chile18$b47a) <- NULL
val_labels(Chile18$ing4) <- NULL
val_labels(Chile18$pn4) <- NULL

#Variáveis independentes
val_labels(Chile18$vic1ext) <- NULL
val_labels(Chile18$aoj11) <- NULL
val_labels(Chile18$it1) <- NULL
val_labels(Chile18$jc10) <- NULL
val_labels(Chile18$jc13) <- NULL
val_labels(Chile18$q1) <- NULL
val_labels(Chile18$q2) <- NULL
val_labels(Chile18$ed) <- NULL
val_labels(Chile18$q10new) <- NULL
val_labels(Chile18$etid) <- NULL
val_labels(Chile18$soct2) <- NULL
val_labels(Chile18$idio2) <- NULL
val_labels(Chile18$infrax) <- NULL
val_labels(Chile18$exc14) <- NULL
val_labels(Chile18$cp8) <- NULL
val_labels(Chile18$prot3) <- NULL
val_labels(Chile18$vb2) <- NULL

save(Chile18, file="CHI18.RData")

#Colômbia
Colombia16 <- read_dta("Colombia_16.dta")

val_labels(Colombia16$pais) <- NULL
val_labels(Colombia16$wt) <- NULL
val_labels(Colombia16$ur) <- NULL
val_labels(Colombia16$a4) <- NULL

#Variáveis dependentes
val_labels(Colombia16$b1) <- NULL
val_labels(Colombia16$b2) <- NULL
val_labels(Colombia16$b3) <- NULL 
val_labels(Colombia16$b4) <- NULL 
val_labels(Colombia16$b6) <- NULL 
val_labels(Colombia16$b13) <- NULL
val_labels(Colombia16$b18) <- NULL
val_labels(Colombia16$b21) <- NULL
val_labels(Colombia16$b21a) <- NULL
val_labels(Colombia16$b32) <- NULL
val_labels(Colombia16$b37) <- NULL
val_labels(Colombia16$b47a) <- NULL
val_labels(Colombia16$ing4) <- NULL
val_labels(Colombia16$pn4) <- NULL

#Variáveis independentes
val_labels(Colombia16$vic1ext) <- NULL
val_labels(Colombia16$aoj11) <- NULL
val_labels(Colombia16$it1) <- NULL
val_labels(Colombia16$jc10) <- NULL
val_labels(Colombia16$jc13) <- NULL
val_labels(Colombia16$q1) <- NULL
val_labels(Colombia16$q2) <- NULL
val_labels(Colombia16$ed) <- NULL
val_labels(Colombia16$q10new) <- NULL
val_labels(Colombia16$etid) <- NULL
val_labels(Colombia16$soct2) <- NULL
val_labels(Colombia16$idio2) <- NULL
val_labels(Colombia16$infrax) <- NULL
val_labels(Colombia16$exc14) <- NULL
val_labels(Colombia16$cp8) <- NULL
val_labels(Colombia16$prot3) <- NULL
val_labels(Colombia16$vb2) <- NULL

save(Colombia16, file="COL16.RData")

#Colombia 2018
Colombia18 <- read_dta("Colombia_18.dta")

val_labels(Colombia18$pais) <- NULL
val_labels(Colombia18$wt) <- NULL
val_labels(Colombia18$ur) <- NULL
val_labels(Colombia18$a4) <- NULL

#Variáveis dependentes
val_labels(Colombia18$b1) <- NULL
val_labels(Colombia18$b2) <- NULL
val_labels(Colombia18$b3) <- NULL 
val_labels(Colombia18$b4) <- NULL 
val_labels(Colombia18$b6) <- NULL 
val_labels(Colombia18$b13) <- NULL
val_labels(Colombia18$b18) <- NULL
val_labels(Colombia18$b21) <- NULL
val_labels(Colombia18$b21a) <- NULL
val_labels(Colombia18$b32) <- NULL
val_labels(Colombia18$b37) <- NULL
val_labels(Colombia18$b47a) <- NULL
val_labels(Colombia18$ing4) <- NULL
val_labels(Colombia18$pn4) <- NULL

#Variáveis independentes
val_labels(Colombia18$vic1ext) <- NULL
val_labels(Colombia18$aoj11) <- NULL
val_labels(Colombia18$it1) <- NULL
val_labels(Colombia18$jc10) <- NULL
val_labels(Colombia18$jc13) <- NULL
val_labels(Colombia18$q1) <- NULL
val_labels(Colombia18$q2) <- NULL
val_labels(Colombia18$ed) <- NULL
val_labels(Colombia18$q10new) <- NULL
val_labels(Colombia18$etid) <- NULL
val_labels(Colombia18$soct2) <- NULL
val_labels(Colombia18$idio2) <- NULL
val_labels(Colombia18$infrax) <- NULL
val_labels(Colombia18$exc14) <- NULL
val_labels(Colombia18$cp8) <- NULL
val_labels(Colombia18$prot3) <- NULL
val_labels(Colombia18$vb2) <- NULL

save(Colombia18, file="COL18.RData")

#Costa Rica
CostaRica16 <- read_dta("CostaRica_16.dta")

val_labels(CostaRica16$pais) <- NULL
val_labels(CostaRica16$wt) <- NULL
val_labels(CostaRica16$ur) <- NULL
val_labels(CostaRica16$a4) <- NULL

#Variáveis dependentes
val_labels(CostaRica16$b1) <- NULL
val_labels(CostaRica16$b2) <- NULL
val_labels(CostaRica16$b3) <- NULL 
val_labels(CostaRica16$b4) <- NULL 
val_labels(CostaRica16$b6) <- NULL 
val_labels(CostaRica16$b13) <- NULL
val_labels(CostaRica16$b18) <- NULL
val_labels(CostaRica16$b21) <- NULL
val_labels(CostaRica16$b21a) <- NULL
val_labels(CostaRica16$b32) <- NULL
val_labels(CostaRica16$b37) <- NULL
val_labels(CostaRica16$b47a) <- NULL
val_labels(CostaRica16$ing4) <- NULL
val_labels(CostaRica16$pn4) <- NULL

#Variáveis independentes
val_labels(CostaRica16$vic1ext) <- NULL
val_labels(CostaRica16$aoj11) <- NULL
val_labels(CostaRica16$it1) <- NULL
val_labels(CostaRica16$jc10) <- NULL
val_labels(CostaRica16$jc13) <- NULL
val_labels(CostaRica16$q1) <- NULL
val_labels(CostaRica16$q2) <- NULL
val_labels(CostaRica16$ed) <- NULL
val_labels(CostaRica16$q10new) <- NULL
val_labels(CostaRica16$etid) <- NULL
val_labels(CostaRica16$soct2) <- NULL
val_labels(CostaRica16$idio2) <- NULL
val_labels(CostaRica16$infrax) <- NULL
val_labels(CostaRica16$exc14) <- NULL
val_labels(CostaRica16$cp8) <- NULL
val_labels(CostaRica16$prot3) <- NULL
val_labels(CostaRica16$vb2) <- NULL

save(CostaRica16, file="COS16.RData")

#Costa Rica 2018
CostaRica18 <- read_dta("CostaRica_18.dta")

val_labels(CostaRica18$pais) <- NULL
val_labels(CostaRica18$wt) <- NULL
val_labels(CostaRica18$ur) <- NULL
val_labels(CostaRica18$a4) <- NULL

#Variáveis dependentes
val_labels(CostaRica18$b1) <- NULL
val_labels(CostaRica18$b2) <- NULL
val_labels(CostaRica18$b3) <- NULL 
val_labels(CostaRica18$b4) <- NULL 
val_labels(CostaRica18$b6) <- NULL 
val_labels(CostaRica18$b13) <- NULL
val_labels(CostaRica18$b18) <- NULL
val_labels(CostaRica18$b21) <- NULL
val_labels(CostaRica18$b21a) <- NULL
val_labels(CostaRica18$b32) <- NULL
val_labels(CostaRica18$b37) <- NULL
val_labels(CostaRica18$b47a) <- NULL
val_labels(CostaRica18$ing4) <- NULL
val_labels(CostaRica18$pn4) <- NULL

#Variáveis independentes
val_labels(CostaRica18$vic1ext) <- NULL
val_labels(CostaRica18$aoj11) <- NULL
val_labels(CostaRica18$it1) <- NULL
val_labels(CostaRica18$jc10) <- NULL
val_labels(CostaRica18$jc13) <- NULL
val_labels(CostaRica18$q1) <- NULL
val_labels(CostaRica18$q2) <- NULL
val_labels(CostaRica18$ed) <- NULL
val_labels(CostaRica18$q10new) <- NULL
val_labels(CostaRica18$etid) <- NULL
val_labels(CostaRica18$soct2) <- NULL
val_labels(CostaRica18$idio2) <- NULL
val_labels(CostaRica18$infrax) <- NULL
val_labels(CostaRica18$exc14) <- NULL
val_labels(CostaRica18$cp8) <- NULL
val_labels(CostaRica18$prot3) <- NULL
val_labels(CostaRica18$vb2) <- NULL

save(CostaRica18, file="COS18.RData")


#El Salvador
ElSalvador16 <- read_dta("ElSalvador_16.dta")

val_labels(ElSalvador16$pais) <- NULL
val_labels(ElSalvador16$wt) <- NULL
val_labels(ElSalvador16$ur) <- NULL
val_labels(ElSalvador16$a4) <- NULL

#Variáveis dependentes
val_labels(ElSalvador16$b1) <- NULL
val_labels(ElSalvador16$b2) <- NULL
val_labels(ElSalvador16$b3) <- NULL 
val_labels(ElSalvador16$b4) <- NULL 
val_labels(ElSalvador16$b6) <- NULL 
val_labels(ElSalvador16$b13) <- NULL
val_labels(ElSalvador16$b18) <- NULL
val_labels(ElSalvador16$b21) <- NULL
val_labels(ElSalvador16$b21a) <- NULL
val_labels(ElSalvador16$b32) <- NULL
val_labels(ElSalvador16$b37) <- NULL
val_labels(ElSalvador16$b47a) <- NULL
val_labels(ElSalvador16$ing4) <- NULL
val_labels(ElSalvador16$pn4) <- NULL

#Variáveis independentes
val_labels(ElSalvador16$vic1ext) <- NULL
val_labels(ElSalvador16$aoj11) <- NULL
val_labels(ElSalvador16$it1) <- NULL
val_labels(ElSalvador16$jc10) <- NULL
val_labels(ElSalvador16$jc13) <- NULL
val_labels(ElSalvador16$q1) <- NULL
val_labels(ElSalvador16$q2) <- NULL
val_labels(ElSalvador16$ed) <- NULL
val_labels(ElSalvador16$q10new) <- NULL
val_labels(ElSalvador16$etid) <- NULL
val_labels(ElSalvador16$soct2) <- NULL
val_labels(ElSalvador16$idio2) <- NULL
val_labels(ElSalvador16$infrax) <- NULL
val_labels(ElSalvador16$exc14) <- NULL
val_labels(ElSalvador16$cp8) <- NULL
val_labels(ElSalvador16$prot3) <- NULL
val_labels(ElSalvador16$vb2) <- NULL

save(ElSalvador16, file="ELS16.RData")

#El Salvador 2018
ElSalvador18 <- read_dta("ElSalvador_18.dta")

val_labels(ElSalvador18$pais) <- NULL
val_labels(ElSalvador18$wt) <- NULL
val_labels(ElSalvador18$ur) <- NULL
val_labels(ElSalvador18$a4) <- NULL

#Variáveis dependentes
val_labels(ElSalvador18$b1) <- NULL
val_labels(ElSalvador18$b2) <- NULL
val_labels(ElSalvador18$b3) <- NULL 
val_labels(ElSalvador18$b4) <- NULL 
val_labels(ElSalvador18$b6) <- NULL 
val_labels(ElSalvador18$b13) <- NULL
val_labels(ElSalvador18$b18) <- NULL
val_labels(ElSalvador18$b21) <- NULL
val_labels(ElSalvador18$b21a) <- NULL
val_labels(ElSalvador18$b32) <- NULL
val_labels(ElSalvador18$b37) <- NULL
val_labels(ElSalvador18$b47a) <- NULL
val_labels(ElSalvador18$ing4) <- NULL
val_labels(ElSalvador18$pn4) <- NULL

#Variáveis independentes
val_labels(ElSalvador18$vic1ext) <- NULL
val_labels(ElSalvador18$aoj11) <- NULL
val_labels(ElSalvador18$it1) <- NULL
val_labels(ElSalvador18$jc10) <- NULL
val_labels(ElSalvador18$jc13) <- NULL
val_labels(ElSalvador18$q1) <- NULL
val_labels(ElSalvador18$q2) <- NULL
val_labels(ElSalvador18$ed) <- NULL
val_labels(ElSalvador18$q10new) <- NULL
val_labels(ElSalvador18$etid) <- NULL
val_labels(ElSalvador18$soct2) <- NULL
val_labels(ElSalvador18$idio2) <- NULL
val_labels(ElSalvador18$infrax) <- NULL
val_labels(ElSalvador18$exc14) <- NULL
val_labels(ElSalvador18$cp8) <- NULL
val_labels(ElSalvador18$prot3) <- NULL
val_labels(ElSalvador18$vb2) <- NULL

save(ElSalvador18, file="ELS18.RData")


#Equador
Equador16 <- read_dta("Equador_16.dta")

val_labels(Equador16$pais) <- NULL
val_labels(Equador16$wt) <- NULL
val_labels(Equador16$ur) <- NULL
val_labels(Equador16$a4) <- NULL

#Variáveis dependentes
val_labels(Equador16$b1) <- NULL
val_labels(Equador16$b2) <- NULL
val_labels(Equador16$b3) <- NULL 
val_labels(Equador16$b4) <- NULL 
val_labels(Equador16$b6) <- NULL 
val_labels(Equador16$b13) <- NULL
val_labels(Equador16$b18) <- NULL
val_labels(Equador16$b21) <- NULL
val_labels(Equador16$b21a) <- NULL
val_labels(Equador16$b32) <- NULL
val_labels(Equador16$b37) <- NULL
val_labels(Equador16$b47a) <- NULL
val_labels(Equador16$ing4) <- NULL
val_labels(Equador16$pn4) <- NULL

#Variáveis independentes
val_labels(Equador16$vic1ext) <- NULL
val_labels(Equador16$aoj11) <- NULL
val_labels(Equador16$it1) <- NULL
val_labels(Equador16$jc10) <- NULL
val_labels(Equador16$jc13) <- NULL
val_labels(Equador16$q1) <- NULL
val_labels(Equador16$q2) <- NULL
val_labels(Equador16$ed) <- NULL
val_labels(Equador16$q10new) <- NULL
val_labels(Equador16$etid) <- NULL
val_labels(Equador16$soct2) <- NULL
val_labels(Equador16$idio2) <- NULL
val_labels(Equador16$infrax) <- NULL
val_labels(Equador16$exc14) <- NULL
val_labels(Equador16$cp8) <- NULL
val_labels(Equador16$prot3) <- NULL
val_labels(Equador16$vb2) <- NULL

save(Equador16, file="EQU16.RData")

#Equador 2018
Equador18 <- read_dta("Equador_18.dta")

val_labels(Equador18$pais) <- NULL
val_labels(Equador18$wt) <- NULL
val_labels(Equador18$ur) <- NULL
val_labels(Equador18$a4) <- NULL

#Variáveis dependentes
val_labels(Equador18$b1) <- NULL
val_labels(Equador18$b2) <- NULL
val_labels(Equador18$b3) <- NULL 
val_labels(Equador18$b4) <- NULL 
val_labels(Equador18$b6) <- NULL 
val_labels(Equador18$b13) <- NULL
val_labels(Equador18$b18) <- NULL
val_labels(Equador18$b21) <- NULL
val_labels(Equador18$b21a) <- NULL
val_labels(Equador18$b32) <- NULL
val_labels(Equador18$b37) <- NULL
val_labels(Equador18$b47a) <- NULL
val_labels(Equador18$ing4) <- NULL
val_labels(Equador18$pn4) <- NULL

#Variáveis independentes
val_labels(Equador18$vic1ext) <- NULL
val_labels(Equador18$aoj11) <- NULL
val_labels(Equador18$it1) <- NULL
val_labels(Equador18$jc10) <- NULL
val_labels(Equador18$jc13) <- NULL
val_labels(Equador18$q1) <- NULL
val_labels(Equador18$q2) <- NULL
val_labels(Equador18$ed) <- NULL
val_labels(Equador18$q10new) <- NULL
val_labels(Equador18$etid) <- NULL
val_labels(Equador18$soct2) <- NULL
val_labels(Equador18$idio2) <- NULL
val_labels(Equador18$infrax) <- NULL
val_labels(Equador18$exc14) <- NULL
val_labels(Equador18$cp8) <- NULL
val_labels(Equador18$prot3) <- NULL
val_labels(Equador18$vb2) <- NULL

save(Equador18, file="EQU18.RData")


#Guatemala
Guatemala16 <- read_dta("Guatemala_16.dta")

val_labels(Guatemala16$pais) <- NULL
val_labels(Guatemala16$wt) <- NULL
val_labels(Guatemala16$ur) <- NULL
val_labels(Guatemala16$a4) <- NULL

#Variáveis dependentes
val_labels(Guatemala16$b1) <- NULL
val_labels(Guatemala16$b2) <- NULL
val_labels(Guatemala16$b3) <- NULL 
val_labels(Guatemala16$b4) <- NULL 
val_labels(Guatemala16$b6) <- NULL 
val_labels(Guatemala16$b13) <- NULL
val_labels(Guatemala16$b18) <- NULL
val_labels(Guatemala16$b21) <- NULL
val_labels(Guatemala16$b21a) <- NULL
val_labels(Guatemala16$b32) <- NULL
val_labels(Guatemala16$b37) <- NULL
val_labels(Guatemala16$b47a) <- NULL
val_labels(Guatemala16$ing4) <- NULL
val_labels(Guatemala16$pn4) <- NULL

#Variáveis independentes
val_labels(Guatemala16$vic1ext) <- NULL
val_labels(Guatemala16$aoj11) <- NULL
val_labels(Guatemala16$it1) <- NULL
val_labels(Guatemala16$jc10) <- NULL
val_labels(Guatemala16$jc13) <- NULL
val_labels(Guatemala16$q1) <- NULL
val_labels(Guatemala16$q2) <- NULL
val_labels(Guatemala16$ed) <- NULL
val_labels(Guatemala16$q10new) <- NULL
val_labels(Guatemala16$etid) <- NULL
val_labels(Guatemala16$soct2) <- NULL
val_labels(Guatemala16$idio2) <- NULL
val_labels(Guatemala16$infrax) <- NULL
val_labels(Guatemala16$exc14) <- NULL
val_labels(Guatemala16$cp8) <- NULL
val_labels(Guatemala16$prot3) <- NULL
val_labels(Guatemala16$vb2) <- NULL

save(Guatemala16, file="GUA16.RData")

#Guatemala 2018
Guatemala18 <- read_dta("Guatemala_18.dta")

val_labels(Guatemala18$pais) <- NULL
val_labels(Guatemala18$wt) <- NULL
val_labels(Guatemala18$ur) <- NULL
val_labels(Guatemala18$a4) <- NULL

#Variáveis dependentes
val_labels(Guatemala18$b1) <- NULL
val_labels(Guatemala18$b2) <- NULL
val_labels(Guatemala18$b3) <- NULL 
val_labels(Guatemala18$b4) <- NULL 
val_labels(Guatemala18$b6) <- NULL 
val_labels(Guatemala18$b13) <- NULL
val_labels(Guatemala18$b18) <- NULL
val_labels(Guatemala18$b21) <- NULL
val_labels(Guatemala18$b21a) <- NULL
val_labels(Guatemala18$b32) <- NULL
val_labels(Guatemala18$b37) <- NULL
val_labels(Guatemala18$b47a) <- NULL
val_labels(Guatemala18$ing4) <- NULL
val_labels(Guatemala18$pn4) <- NULL

#Variáveis independentes
val_labels(Guatemala18$vic1ext) <- NULL
val_labels(Guatemala18$aoj11) <- NULL
val_labels(Guatemala18$it1) <- NULL
val_labels(Guatemala18$jc10) <- NULL
val_labels(Guatemala18$jc13) <- NULL
val_labels(Guatemala18$q1) <- NULL
val_labels(Guatemala18$q2) <- NULL
val_labels(Guatemala18$ed) <- NULL
val_labels(Guatemala18$q10new) <- NULL
val_labels(Guatemala18$etid) <- NULL
val_labels(Guatemala18$soct2) <- NULL
val_labels(Guatemala18$idio2) <- NULL
val_labels(Guatemala18$infrax) <- NULL
val_labels(Guatemala18$exc14) <- NULL
val_labels(Guatemala18$cp8) <- NULL
val_labels(Guatemala18$prot3) <- NULL
val_labels(Guatemala18$vb2) <- NULL

save(Guatemala18, file="GUA18.RData")

#Honduras
Honduras16 <- read_dta("Honduras_16.dta")

val_labels(Honduras16$pais) <- NULL
val_labels(Honduras16$wt) <- NULL
val_labels(Honduras16$ur) <- NULL
val_labels(Honduras16$a4) <- NULL

#Variáveis dependentes
val_labels(Honduras16$b1) <- NULL
val_labels(Honduras16$b2) <- NULL
val_labels(Honduras16$b3) <- NULL 
val_labels(Honduras16$b4) <- NULL 
val_labels(Honduras16$b6) <- NULL 
val_labels(Honduras16$b13) <- NULL
val_labels(Honduras16$b18) <- NULL
val_labels(Honduras16$b21) <- NULL
val_labels(Honduras16$b21a) <- NULL
val_labels(Honduras16$b32) <- NULL
val_labels(Honduras16$b37) <- NULL
val_labels(Honduras16$b47a) <- NULL
val_labels(Honduras16$ing4) <- NULL
val_labels(Honduras16$pn4) <- NULL

#Variáveis independentes
val_labels(Honduras16$vic1ext) <- NULL
val_labels(Honduras16$aoj11) <- NULL
val_labels(Honduras16$it1) <- NULL
val_labels(Honduras16$jc10) <- NULL
val_labels(Honduras16$jc13) <- NULL
val_labels(Honduras16$q1) <- NULL
val_labels(Honduras16$q2) <- NULL
val_labels(Honduras16$ed) <- NULL
val_labels(Honduras16$q10new) <- NULL
val_labels(Honduras16$etid) <- NULL
val_labels(Honduras16$soct2) <- NULL
val_labels(Honduras16$idio2) <- NULL
val_labels(Honduras16$infrax) <- NULL
val_labels(Honduras16$exc14) <- NULL
val_labels(Honduras16$cp8) <- NULL
val_labels(Honduras16$prot3) <- NULL
val_labels(Honduras16$vb2) <- NULL

save(Honduras16, file="HON16.RData")

#Honduras 2018
Honduras18 <- read_dta("Honduras_18.dta")

val_labels(Honduras18$pais) <- NULL
val_labels(Honduras18$wt) <- NULL
val_labels(Honduras18$ur) <- NULL
val_labels(Honduras18$a4) <- NULL

#Variáveis dependentes
val_labels(Honduras18$b1) <- NULL
val_labels(Honduras18$b2) <- NULL
val_labels(Honduras18$b3) <- NULL 
val_labels(Honduras18$b4) <- NULL 
val_labels(Honduras18$b6) <- NULL 
val_labels(Honduras18$b13) <- NULL
val_labels(Honduras18$b18) <- NULL
val_labels(Honduras18$b21) <- NULL
val_labels(Honduras18$b21a) <- NULL
val_labels(Honduras18$b32) <- NULL
val_labels(Honduras18$b37) <- NULL
val_labels(Honduras18$b47a) <- NULL
val_labels(Honduras18$ing4) <- NULL
val_labels(Honduras18$pn4) <- NULL

#Variáveis independentes
val_labels(Honduras18$vic1ext) <- NULL
val_labels(Honduras18$aoj11) <- NULL
val_labels(Honduras18$it1) <- NULL
val_labels(Honduras18$jc10) <- NULL
val_labels(Honduras18$jc13) <- NULL
val_labels(Honduras18$q1) <- NULL
val_labels(Honduras18$q2) <- NULL
val_labels(Honduras18$ed) <- NULL
val_labels(Honduras18$q10new) <- NULL
val_labels(Honduras18$etid) <- NULL
val_labels(Honduras18$soct2) <- NULL
val_labels(Honduras18$idio2) <- NULL
val_labels(Honduras18$infrax) <- NULL
val_labels(Honduras18$exc14) <- NULL
val_labels(Honduras18$cp8) <- NULL
val_labels(Honduras18$prot3) <- NULL
val_labels(Honduras18$vb2) <- NULL

save(Honduras18, file="HON18.RData")


#México
Mexico16 <- read_dta("Mexico_16.dta")

val_labels(Mexico16$pais) <- NULL
val_labels(Mexico16$wt) <- NULL
val_labels(Mexico16$ur) <- NULL
val_labels(Mexico16$a4) <- NULL

#Variáveis dependentes
val_labels(Mexico16$b1) <- NULL
val_labels(Mexico16$b2) <- NULL
val_labels(Mexico16$b3) <- NULL 
val_labels(Mexico16$b4) <- NULL 
val_labels(Mexico16$b6) <- NULL 
val_labels(Mexico16$b13) <- NULL
val_labels(Mexico16$b18) <- NULL
val_labels(Mexico16$b21) <- NULL
val_labels(Mexico16$b21a) <- NULL
val_labels(Mexico16$b32) <- NULL
val_labels(Mexico16$b37) <- NULL
val_labels(Mexico16$b47a) <- NULL
val_labels(Mexico16$ing4) <- NULL
val_labels(Mexico16$pn4) <- NULL

#Variáveis independentes
val_labels(Mexico16$vic1ext) <- NULL
val_labels(Mexico16$aoj11) <- NULL
val_labels(Mexico16$it1) <- NULL
val_labels(Mexico16$jc10) <- NULL
val_labels(Mexico16$jc13) <- NULL
val_labels(Mexico16$q1) <- NULL
val_labels(Mexico16$q2) <- NULL
val_labels(Mexico16$ed) <- NULL
val_labels(Mexico16$q10new) <- NULL
val_labels(Mexico16$etid) <- NULL
val_labels(Mexico16$soct2) <- NULL
val_labels(Mexico16$idio2) <- NULL
val_labels(Mexico16$infrax) <- NULL
val_labels(Mexico16$exc14) <- NULL
val_labels(Mexico16$cp8) <- NULL
val_labels(Mexico16$prot3) <- NULL
val_labels(Mexico16$vb2) <- NULL

save(Mexico16, file="MEX16.RData")

#México 2018
Mexico18 <- read_dta("Mexico_18.dta")

val_labels(Mexico18$pais) <- NULL
val_labels(Mexico18$wt) <- NULL
val_labels(Mexico18$ur) <- NULL
val_labels(Mexico18$a4) <- NULL

#Variáveis dependentes
val_labels(Mexico18$b1) <- NULL
val_labels(Mexico18$b2) <- NULL
val_labels(Mexico18$b3) <- NULL 
val_labels(Mexico18$b4) <- NULL 
val_labels(Mexico18$b6) <- NULL 
val_labels(Mexico18$b13) <- NULL
val_labels(Mexico18$b18) <- NULL
val_labels(Mexico18$b21) <- NULL
val_labels(Mexico18$b21a) <- NULL
val_labels(Mexico18$b32) <- NULL
val_labels(Mexico18$b37) <- NULL
val_labels(Mexico18$b47a) <- NULL
val_labels(Mexico18$ing4) <- NULL
val_labels(Mexico18$pn4) <- NULL

#Variáveis independentes
val_labels(Mexico18$vic1ext) <- NULL
val_labels(Mexico18$aoj11) <- NULL
val_labels(Mexico18$it1) <- NULL
val_labels(Mexico18$jc10) <- NULL
val_labels(Mexico18$jc13) <- NULL
val_labels(Mexico18$q1) <- NULL
val_labels(Mexico18$q2) <- NULL
val_labels(Mexico18$ed) <- NULL
val_labels(Mexico18$q10new) <- NULL
val_labels(Mexico18$etid) <- NULL
val_labels(Mexico18$soct2) <- NULL
val_labels(Mexico18$idio2) <- NULL
val_labels(Mexico18$infrax) <- NULL
val_labels(Mexico18$exc14) <- NULL
val_labels(Mexico18$cp8) <- NULL
val_labels(Mexico18$prot3) <- NULL
val_labels(Mexico18$vb2) <- NULL

save(Mexico18, file="MEX18.RData")

#Nicarágua
Nicaragua16 <- read_dta("Nicaragua_16.dta")

val_labels(Nicaragua16$pais) <- NULL
val_labels(Nicaragua16$wt) <- NULL
val_labels(Nicaragua16$ur) <- NULL
val_labels(Nicaragua16$a4) <- NULL

#Variáveis dependentes
val_labels(Nicaragua16$b1) <- NULL
val_labels(Nicaragua16$b2) <- NULL
val_labels(Nicaragua16$b3) <- NULL 
val_labels(Nicaragua16$b4) <- NULL 
val_labels(Nicaragua16$b6) <- NULL 
val_labels(Nicaragua16$b13) <- NULL
val_labels(Nicaragua16$b18) <- NULL
val_labels(Nicaragua16$b21) <- NULL
val_labels(Nicaragua16$b21a) <- NULL
val_labels(Nicaragua16$b32) <- NULL
val_labels(Nicaragua16$b37) <- NULL
val_labels(Nicaragua16$b47a) <- NULL
val_labels(Nicaragua16$ing4) <- NULL
val_labels(Nicaragua16$pn4) <- NULL

#Variáveis independentes
val_labels(Nicaragua16$vic1ext) <- NULL
val_labels(Nicaragua16$aoj11) <- NULL
val_labels(Nicaragua16$it1) <- NULL
val_labels(Nicaragua16$jc10) <- NULL
val_labels(Nicaragua16$jc13) <- NULL
val_labels(Nicaragua16$q1) <- NULL
val_labels(Nicaragua16$q2) <- NULL
val_labels(Nicaragua16$ed) <- NULL
val_labels(Nicaragua16$q10new) <- NULL
val_labels(Nicaragua16$etid) <- NULL
val_labels(Nicaragua16$soct2) <- NULL
val_labels(Nicaragua16$idio2) <- NULL
val_labels(Nicaragua16$infrax) <- NULL
val_labels(Nicaragua16$exc14) <- NULL
val_labels(Nicaragua16$cp8) <- NULL
val_labels(Nicaragua16$prot3) <- NULL
val_labels(Nicaragua16$vb2) <- NULL

save(Nicaragua16, file="NIC16.RData")

#México 2018
Nicaragua18 <- read_dta("Nicaragua_18.dta")

val_labels(Nicaragua18$pais) <- NULL
val_labels(Nicaragua18$wt) <- NULL
val_labels(Nicaragua18$ur) <- NULL
val_labels(Nicaragua18$a4) <- NULL

#Variáveis dependentes
val_labels(Nicaragua18$b1) <- NULL
val_labels(Nicaragua18$b2) <- NULL
val_labels(Nicaragua18$b3) <- NULL 
val_labels(Nicaragua18$b4) <- NULL 
val_labels(Nicaragua18$b6) <- NULL 
val_labels(Nicaragua18$b13) <- NULL
val_labels(Nicaragua18$b18) <- NULL
val_labels(Nicaragua18$b21) <- NULL
val_labels(Nicaragua18$b21a) <- NULL
val_labels(Nicaragua18$b32) <- NULL
val_labels(Nicaragua18$b37) <- NULL
val_labels(Nicaragua18$b47a) <- NULL
val_labels(Nicaragua18$ing4) <- NULL
val_labels(Nicaragua18$pn4) <- NULL

#Variáveis independentes
val_labels(Nicaragua18$vic1ext) <- NULL
val_labels(Nicaragua18$aoj11) <- NULL
val_labels(Nicaragua18$it1) <- NULL
val_labels(Nicaragua18$jc10) <- NULL
val_labels(Nicaragua18$jc13) <- NULL
val_labels(Nicaragua18$q1) <- NULL
val_labels(Nicaragua18$q2) <- NULL
val_labels(Nicaragua18$ed) <- NULL
val_labels(Nicaragua18$q10new) <- NULL
val_labels(Nicaragua18$etid) <- NULL
val_labels(Nicaragua18$soct2) <- NULL
val_labels(Nicaragua18$idio2) <- NULL
val_labels(Nicaragua18$infrax) <- NULL
val_labels(Nicaragua18$exc14) <- NULL
val_labels(Nicaragua18$cp8) <- NULL
val_labels(Nicaragua18$prot3) <- NULL
val_labels(Nicaragua18$vb2) <- NULL

save(Nicaragua18, file="NIC18.RData")


#Panamá
Panama16 <- read_dta("Panama_16.dta")

val_labels(Panama16$pais) <- NULL
val_labels(Panama16$wt) <- NULL
val_labels(Panama16$ur) <- NULL
val_labels(Panama16$a4) <- NULL

#Variáveis dependentes
val_labels(Panama16$b1) <- NULL
val_labels(Panama16$b2) <- NULL
val_labels(Panama16$b3) <- NULL 
val_labels(Panama16$b4) <- NULL 
val_labels(Panama16$b6) <- NULL 
val_labels(Panama16$b13) <- NULL
val_labels(Panama16$b18) <- NULL
val_labels(Panama16$b21) <- NULL
val_labels(Panama16$b21a) <- NULL
val_labels(Panama16$b32) <- NULL
val_labels(Panama16$b37) <- NULL
val_labels(Panama16$b47a) <- NULL
val_labels(Panama16$ing4) <- NULL
val_labels(Panama16$pn4) <- NULL

#Variáveis independentes
val_labels(Panama16$vic1ext) <- NULL
val_labels(Panama16$aoj11) <- NULL
val_labels(Panama16$it1) <- NULL
val_labels(Panama16$jc10) <- NULL
val_labels(Panama16$jc13) <- NULL
val_labels(Panama16$q1) <- NULL
val_labels(Panama16$q2) <- NULL
val_labels(Panama16$ed) <- NULL
val_labels(Panama16$q10new) <- NULL
val_labels(Panama16$etid) <- NULL
val_labels(Panama16$soct2) <- NULL
val_labels(Panama16$idio2) <- NULL
val_labels(Panama16$infrax) <- NULL
val_labels(Panama16$exc14) <- NULL
val_labels(Panama16$cp8) <- NULL
val_labels(Panama16$prot3) <- NULL
val_labels(Panama16$vb2) <- NULL

save(Panama16, file="PAN16.RData")

#Panamá 2018
Panama18 <- read_dta("Panama_18.dta")

val_labels(Panama18$pais) <- NULL
val_labels(Panama18$wt) <- NULL
val_labels(Panama18$ur) <- NULL
val_labels(Panama18$a4) <- NULL

#Variáveis dependentes
val_labels(Panama18$b1) <- NULL
val_labels(Panama18$b2) <- NULL
val_labels(Panama18$b3) <- NULL 
val_labels(Panama18$b4) <- NULL 
val_labels(Panama18$b6) <- NULL 
val_labels(Panama18$b13) <- NULL
val_labels(Panama18$b18) <- NULL
val_labels(Panama18$b21) <- NULL
val_labels(Panama18$b21a) <- NULL
val_labels(Panama18$b32) <- NULL
val_labels(Panama18$b37) <- NULL
val_labels(Panama18$b47a) <- NULL
val_labels(Panama18$ing4) <- NULL
val_labels(Panama18$pn4) <- NULL

#Variáveis independentes
val_labels(Panama18$vic1ext) <- NULL
val_labels(Panama18$aoj11) <- NULL
val_labels(Panama18$it1) <- NULL
val_labels(Panama18$jc10) <- NULL
val_labels(Panama18$jc13) <- NULL
val_labels(Panama18$q1) <- NULL
val_labels(Panama18$q2) <- NULL
val_labels(Panama18$ed) <- NULL
val_labels(Panama18$q10new) <- NULL
val_labels(Panama18$etid) <- NULL
val_labels(Panama18$soct2) <- NULL
val_labels(Panama18$idio2) <- NULL
val_labels(Panama18$infrax) <- NULL
val_labels(Panama18$exc14) <- NULL
val_labels(Panama18$cp8) <- NULL
val_labels(Panama18$prot3) <- NULL
val_labels(Panama18$vb2) <- NULL

save(Panama18, file="PAN18.RData")

#Paraguai
Paraguai16 <- read_dta("Paraguai_16.dta")

val_labels(Paraguai16$pais) <- NULL
val_labels(Paraguai16$wt) <- NULL
val_labels(Paraguai16$ur) <- NULL
val_labels(Paraguai16$a4) <- NULL

#Variáveis dependentes
val_labels(Paraguai16$b1) <- NULL
val_labels(Paraguai16$b2) <- NULL
val_labels(Paraguai16$b3) <- NULL 
val_labels(Paraguai16$b4) <- NULL 
val_labels(Paraguai16$b6) <- NULL 
val_labels(Paraguai16$b13) <- NULL
val_labels(Paraguai16$b18) <- NULL
val_labels(Paraguai16$b21) <- NULL
val_labels(Paraguai16$b21a) <- NULL
val_labels(Paraguai16$b32) <- NULL
val_labels(Paraguai16$b37) <- NULL
val_labels(Paraguai16$b47a) <- NULL
val_labels(Paraguai16$ing4) <- NULL
val_labels(Paraguai16$pn4) <- NULL

#Variáveis independentes
val_labels(Paraguai16$vic1ext) <- NULL
val_labels(Paraguai16$aoj11) <- NULL
val_labels(Paraguai16$it1) <- NULL
val_labels(Paraguai16$jc10) <- NULL
val_labels(Paraguai16$jc13) <- NULL
val_labels(Paraguai16$q1) <- NULL
val_labels(Paraguai16$q2) <- NULL
val_labels(Paraguai16$ed) <- NULL
val_labels(Paraguai16$q10new) <- NULL
val_labels(Paraguai16$etid) <- NULL
val_labels(Paraguai16$soct2) <- NULL
val_labels(Paraguai16$idio2) <- NULL
val_labels(Paraguai16$infrax) <- NULL
val_labels(Paraguai16$exc14) <- NULL
val_labels(Paraguai16$cp8) <- NULL
val_labels(Paraguai16$prot3) <- NULL
val_labels(Paraguai16$vb2) <- NULL

save(Paraguai16, file="PAR16.RData")

#Paraguai 2018
Paraguai18 <- read_dta("Paraguai_18.dta")

val_labels(Paraguai18$pais) <- NULL
val_labels(Paraguai18$wt) <- NULL
val_labels(Paraguai18$ur) <- NULL
val_labels(Paraguai18$a4) <- NULL

#Variáveis dependentes
val_labels(Paraguai18$b1) <- NULL
val_labels(Paraguai18$b2) <- NULL
val_labels(Paraguai18$b3) <- NULL 
val_labels(Paraguai18$b4) <- NULL 
val_labels(Paraguai18$b6) <- NULL 
val_labels(Paraguai18$b13) <- NULL
val_labels(Paraguai18$b18) <- NULL
val_labels(Paraguai18$b21) <- NULL
val_labels(Paraguai18$b21a) <- NULL
val_labels(Paraguai18$b32) <- NULL
val_labels(Paraguai18$b37) <- NULL
val_labels(Paraguai18$b47a) <- NULL
val_labels(Paraguai18$ing4) <- NULL
val_labels(Paraguai18$pn4) <- NULL

#Variáveis independentes
val_labels(Paraguai18$vic1ext) <- NULL
val_labels(Paraguai18$aoj11) <- NULL
val_labels(Paraguai18$it1) <- NULL
val_labels(Paraguai18$jc10) <- NULL
val_labels(Paraguai18$jc13) <- NULL
val_labels(Paraguai18$q1) <- NULL
val_labels(Paraguai18$q2) <- NULL
val_labels(Paraguai18$ed) <- NULL
val_labels(Paraguai18$q10new) <- NULL
val_labels(Paraguai18$etid) <- NULL
val_labels(Paraguai18$soct2) <- NULL
val_labels(Paraguai18$idio2) <- NULL
val_labels(Paraguai18$infrax) <- NULL
val_labels(Paraguai18$exc14) <- NULL
val_labels(Paraguai18$cp8) <- NULL
val_labels(Paraguai18$prot3) <- NULL
val_labels(Paraguai18$vb2) <- NULL

save(Paraguai18, file="PAR18.RData")

#Peru
Peru16 <- read_dta("Peru_16.dta")

val_labels(Peru16$pais) <- NULL
val_labels(Peru16$wt) <- NULL
val_labels(Peru16$ur) <- NULL
val_labels(Peru16$a4) <- NULL

#Variáveis dependentes
val_labels(Peru16$b1) <- NULL
val_labels(Peru16$b2) <- NULL
val_labels(Peru16$b3) <- NULL 
val_labels(Peru16$b4) <- NULL 
val_labels(Peru16$b6) <- NULL 
val_labels(Peru16$b13) <- NULL
val_labels(Peru16$b18) <- NULL
val_labels(Peru16$b21) <- NULL
val_labels(Peru16$b21a) <- NULL
val_labels(Peru16$b32) <- NULL
val_labels(Peru16$b37) <- NULL
val_labels(Peru16$b47a) <- NULL
val_labels(Peru16$ing4) <- NULL
val_labels(Peru16$pn4) <- NULL

#Variáveis independentes
val_labels(Peru16$vic1ext) <- NULL
val_labels(Peru16$aoj11) <- NULL
val_labels(Peru16$it1) <- NULL
val_labels(Peru16$jc10) <- NULL
val_labels(Peru16$jc13) <- NULL
val_labels(Peru16$q1) <- NULL
val_labels(Peru16$q2) <- NULL
val_labels(Peru16$ed) <- NULL
val_labels(Peru16$q10new) <- NULL
val_labels(Peru16$etid) <- NULL
val_labels(Peru16$soct2) <- NULL
val_labels(Peru16$idio2) <- NULL
val_labels(Peru16$infrax) <- NULL
val_labels(Peru16$exc14) <- NULL
val_labels(Peru16$cp8) <- NULL
val_labels(Peru16$prot3) <- NULL
val_labels(Peru16$vb2) <- NULL

save(Peru16, file="PER16.RData")

#Peru 2018
Peru18 <- read_dta("Peru_18.dta")

val_labels(Peru18$pais) <- NULL
val_labels(Peru18$wt) <- NULL
val_labels(Peru18$ur) <- NULL
val_labels(Peru18$a4) <- NULL

#Variáveis dependentes
val_labels(Peru18$b1) <- NULL
val_labels(Peru18$b2) <- NULL
val_labels(Peru18$b3) <- NULL 
val_labels(Peru18$b4) <- NULL 
val_labels(Peru18$b6) <- NULL 
val_labels(Peru18$b13) <- NULL
val_labels(Peru18$b18) <- NULL
val_labels(Peru18$b21) <- NULL
val_labels(Peru18$b21a) <- NULL
val_labels(Peru18$b32) <- NULL
val_labels(Peru18$b37) <- NULL
val_labels(Peru18$b47a) <- NULL
val_labels(Peru18$ing4) <- NULL
val_labels(Peru18$pn4) <- NULL

#Variáveis independentes
val_labels(Peru18$vic1ext) <- NULL
val_labels(Peru18$aoj11) <- NULL
val_labels(Peru18$it1) <- NULL
val_labels(Peru18$jc10) <- NULL
val_labels(Peru18$jc13) <- NULL
val_labels(Peru18$q1) <- NULL
val_labels(Peru18$q2) <- NULL
val_labels(Peru18$ed) <- NULL
val_labels(Peru18$q10new) <- NULL
val_labels(Peru18$etid) <- NULL
val_labels(Peru18$soct2) <- NULL
val_labels(Peru18$idio2) <- NULL
val_labels(Peru18$infrax) <- NULL
val_labels(Peru18$exc14) <- NULL
val_labels(Peru18$cp8) <- NULL
val_labels(Peru18$prot3) <- NULL
val_labels(Peru18$vb2) <- NULL

save(Peru18, file="PER18.RData")

#República Dominicana
RepublicaDominicana16 <- read_dta("RepublicaDominicana_16.dta")

val_labels(RepublicaDominicana16$pais) <- NULL
val_labels(RepublicaDominicana16$wt) <- NULL
val_labels(RepublicaDominicana16$ur) <- NULL
val_labels(RepublicaDominicana16$a4) <- NULL

#Variáveis dependentes
val_labels(RepublicaDominicana16$b1) <- NULL
val_labels(RepublicaDominicana16$b2) <- NULL
val_labels(RepublicaDominicana16$b3) <- NULL 
val_labels(RepublicaDominicana16$b4) <- NULL 
val_labels(RepublicaDominicana16$b6) <- NULL 
val_labels(RepublicaDominicana16$b13) <- NULL
val_labels(RepublicaDominicana16$b18) <- NULL
val_labels(RepublicaDominicana16$b21) <- NULL
val_labels(RepublicaDominicana16$b21a) <- NULL
val_labels(RepublicaDominicana16$b32) <- NULL
val_labels(RepublicaDominicana16$b37) <- NULL
val_labels(RepublicaDominicana16$b47a) <- NULL
val_labels(RepublicaDominicana16$ing4) <- NULL
val_labels(RepublicaDominicana16$pn4) <- NULL

#Variáveis independentes
val_labels(RepublicaDominicana16$vic1ext) <- NULL
val_labels(RepublicaDominicana16$aoj11) <- NULL
val_labels(RepublicaDominicana16$it1) <- NULL
val_labels(RepublicaDominicana16$jc10) <- NULL
val_labels(RepublicaDominicana16$jc13) <- NULL
val_labels(RepublicaDominicana16$q1) <- NULL
val_labels(RepublicaDominicana16$q2) <- NULL
val_labels(RepublicaDominicana16$ed) <- NULL
val_labels(RepublicaDominicana16$q10new) <- NULL
val_labels(RepublicaDominicana16$etid) <- NULL
val_labels(RepublicaDominicana16$soct2) <- NULL
val_labels(RepublicaDominicana16$idio2) <- NULL
val_labels(RepublicaDominicana16$infrax) <- NULL
val_labels(RepublicaDominicana16$exc14) <- NULL
val_labels(RepublicaDominicana16$cp8) <- NULL
val_labels(RepublicaDominicana16$prot3) <- NULL
val_labels(RepublicaDominicana16$vb2) <- NULL

save(RepublicaDominicana16, file="REP16.RData")

#República Dominicana 2018
RepublicaDominicana18 <- read_dta("RepublicaDominicana_18.dta")

val_labels(RepublicaDominicana18$pais) <- NULL
val_labels(RepublicaDominicana18$wt) <- NULL
val_labels(RepublicaDominicana18$ur) <- NULL
val_labels(RepublicaDominicana18$a4) <- NULL

#Variáveis dependentes
val_labels(RepublicaDominicana18$b1) <- NULL
val_labels(RepublicaDominicana18$b2) <- NULL
val_labels(RepublicaDominicana18$b3) <- NULL 
val_labels(RepublicaDominicana18$b4) <- NULL 
val_labels(RepublicaDominicana18$b6) <- NULL 
val_labels(RepublicaDominicana18$b13) <- NULL
val_labels(RepublicaDominicana18$b18) <- NULL
val_labels(RepublicaDominicana18$b21) <- NULL
val_labels(RepublicaDominicana18$b21a) <- NULL
val_labels(RepublicaDominicana18$b32) <- NULL
val_labels(RepublicaDominicana18$b37) <- NULL
val_labels(RepublicaDominicana18$b47a) <- NULL
val_labels(RepublicaDominicana18$ing4) <- NULL
val_labels(RepublicaDominicana18$pn4) <- NULL

#Variáveis independentes
val_labels(RepublicaDominicana18$vic1ext) <- NULL
val_labels(RepublicaDominicana18$aoj11) <- NULL
val_labels(RepublicaDominicana18$it1) <- NULL
val_labels(RepublicaDominicana18$jc10) <- NULL
val_labels(RepublicaDominicana18$jc13) <- NULL
val_labels(RepublicaDominicana18$q1) <- NULL
val_labels(RepublicaDominicana18$q2) <- NULL
val_labels(RepublicaDominicana18$ed) <- NULL
val_labels(RepublicaDominicana18$q10new) <- NULL
val_labels(RepublicaDominicana18$etid) <- NULL
val_labels(RepublicaDominicana18$soct2) <- NULL
val_labels(RepublicaDominicana18$idio2) <- NULL
val_labels(RepublicaDominicana18$infrax) <- NULL
val_labels(RepublicaDominicana18$exc14) <- NULL
val_labels(RepublicaDominicana18$cp8) <- NULL
val_labels(RepublicaDominicana18$prot3) <- NULL
val_labels(RepublicaDominicana18$vb2) <- NULL

save(RepublicaDominicana18, file="REP18.RData")

#Uruguai
Uruguai16 <- read_dta("Uruguai_16.dta")

val_labels(Uruguai16$pais) <- NULL
val_labels(Uruguai16$wt) <- NULL
val_labels(Uruguai16$ur) <- NULL
val_labels(Uruguai16$a4) <- NULL

#Variáveis dependentes
val_labels(Uruguai16$b1) <- NULL
val_labels(Uruguai16$b2) <- NULL
val_labels(Uruguai16$b3) <- NULL 
val_labels(Uruguai16$b4) <- NULL 
val_labels(Uruguai16$b6) <- NULL 
val_labels(Uruguai16$b13) <- NULL
val_labels(Uruguai16$b18) <- NULL
val_labels(Uruguai16$b21) <- NULL
val_labels(Uruguai16$b21a) <- NULL
val_labels(Uruguai16$b32) <- NULL
val_labels(Uruguai16$b37) <- NULL
val_labels(Uruguai16$b47a) <- NULL
val_labels(Uruguai16$ing4) <- NULL
val_labels(Uruguai16$pn4) <- NULL

#Variáveis independentes
val_labels(Uruguai16$vic1ext) <- NULL
val_labels(Uruguai16$aoj11) <- NULL
val_labels(Uruguai16$it1) <- NULL
val_labels(Uruguai16$jc10) <- NULL
val_labels(Uruguai16$jc13) <- NULL
val_labels(Uruguai16$q1) <- NULL
val_labels(Uruguai16$q2) <- NULL
val_labels(Uruguai16$ed) <- NULL
val_labels(Uruguai16$q10new) <- NULL
val_labels(Uruguai16$etid) <- NULL
val_labels(Uruguai16$soct2) <- NULL
val_labels(Uruguai16$idio2) <- NULL
val_labels(Uruguai16$infrax) <- NULL
val_labels(Uruguai16$exc14) <- NULL
val_labels(Uruguai16$cp8) <- NULL
val_labels(Uruguai16$prot3) <- NULL
val_labels(Uruguai16$vb2) <- NULL

save(Uruguai16, file="URU16.RData")

#República Dominicana 2018
Uruguai18 <- read_dta("Uruguai_18.dta")

val_labels(Uruguai18$pais) <- NULL
val_labels(Uruguai18$wt) <- NULL
val_labels(Uruguai18$ur) <- NULL
val_labels(Uruguai18$a4) <- NULL

#Variáveis dependentes
val_labels(Uruguai18$b1) <- NULL
val_labels(Uruguai18$b2) <- NULL
val_labels(Uruguai18$b3) <- NULL 
val_labels(Uruguai18$b4) <- NULL 
val_labels(Uruguai18$b6) <- NULL 
val_labels(Uruguai18$b13) <- NULL
val_labels(Uruguai18$b18) <- NULL
val_labels(Uruguai18$b21) <- NULL
val_labels(Uruguai18$b21a) <- NULL
val_labels(Uruguai18$b32) <- NULL
val_labels(Uruguai18$b37) <- NULL
val_labels(Uruguai18$b47a) <- NULL
val_labels(Uruguai18$ing4) <- NULL
val_labels(Uruguai18$pn4) <- NULL

#Variáveis independentes
val_labels(Uruguai18$vic1ext) <- NULL
val_labels(Uruguai18$aoj11) <- NULL
val_labels(Uruguai18$it1) <- NULL
val_labels(Uruguai18$jc10) <- NULL
val_labels(Uruguai18$jc13) <- NULL
val_labels(Uruguai18$q1) <- NULL
val_labels(Uruguai18$q2) <- NULL
val_labels(Uruguai18$ed) <- NULL
val_labels(Uruguai18$q10new) <- NULL
val_labels(Uruguai18$etid) <- NULL
val_labels(Uruguai18$soct2) <- NULL
val_labels(Uruguai18$idio2) <- NULL
val_labels(Uruguai18$infrax) <- NULL
val_labels(Uruguai18$exc14) <- NULL
val_labels(Uruguai18$cp8) <- NULL
val_labels(Uruguai18$prot3) <- NULL
val_labels(Uruguai18$vb2) <- NULL

save(Uruguai18, file="URU18.RData")

### Extração das variáveis

ARG16 <-subset(Argentina16, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))


ARG18 <-subset(Argentina18, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))

BOL16 <-subset(Bolivia16, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))


BOL18 <-subset(Bolivia18, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))

BRA16 <-subset(Brasil16, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))


BRA18 <-subset(Brasil18, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))

CHI16 <-subset(Chile16, select=c("pais", "wt", "ur", "a4",
                                 "b1", "b2", "b3", "b4",
                                 "b6", "b13", "b18","b21",
                                 "b21a", "b32", "b37", "b47a",
                                 "ing4", "pn4", "vic1ext", "aoj11",
                                 "it1", "jc10", "q1",
                                 "q2", "ed", "q10new",
                                 "etid", "soct2", "idio2",
                                 "exc14", "cp8", "prot3", "vb2"))


CHI18 <-subset(Chile18, select=c("pais", "wt", "ur", "a4",
                                 "b1", "b2", "b3", "b4",
                                 "b6", "b13", "b18","b21",
                                 "b21a", "b32", "b37", "b47a",
                                 "ing4", "pn4", "vic1ext", "aoj11",
                                 "it1", "jc10", "q1",
                                 "q2", "ed", "q10new",
                                 "etid", "soct2", "idio2",
                                 "exc14", "cp8", "prot3", "vb2"))


COL16 <-subset(Colombia16, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))


COL18 <-subset(Colombia18, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))

COS16 <-subset(CostaRica16, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))


COS18 <-subset(CostaRica18, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))


ELS16 <-subset(ElSalvador16, select=c("pais", "wt", "ur", "a4",
                                      "b1", "b2", "b3", "b4",
                                      "b6", "b13", "b18","b21",
                                      "b21a", "b32", "b37", "b47a",
                                      "ing4", "pn4", "vic1ext", "aoj11",
                                      "it1", "jc10", "q1",
                                      "q2", "ed", "q10new",
                                      "etid", "soct2", "idio2",
                                      "exc14", "cp8", "prot3", "vb2"))


ELS18 <-subset(ElSalvador18, select=c("pais", "wt", "ur", "a4",
                                      "b1", "b2", "b3", "b4",
                                      "b6", "b13", "b18","b21",
                                      "b21a", "b32", "b37", "b47a",
                                      "ing4", "pn4", "vic1ext", "aoj11",
                                      "it1", "jc10", "q1",
                                      "q2", "ed", "q10new",
                                      "etid", "soct2", "idio2",
                                      "exc14", "cp8", "prot3", "vb2"))

EQU16 <-subset(Equador16, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))


EQU18 <-subset(Equador18, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))

GUA16 <-subset(Guatemala16, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))


GUA18 <-subset(Guatemala18, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))

HON16 <-subset(Honduras16, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))


HON18 <-subset(Honduras18, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))


MEX16 <-subset(Mexico16, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))


MEX18 <-subset(Mexico18, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))

NIC16 <-subset(Nicaragua16, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))


NIC18 <-subset(Nicaragua18, select=c("pais", "wt", "ur", "a4",
                                     "b1", "b2", "b3", "b4",
                                     "b6", "b13", "b18","b21",
                                     "b21a", "b32", "b37", "b47a",
                                     "ing4", "pn4", "vic1ext", "aoj11",
                                     "it1", "jc10", "q1",
                                     "q2", "ed", "q10new",
                                     "etid", "soct2", "idio2",
                                     "exc14", "cp8", "prot3", "vb2"))

#Obs: Nicaragua18 não possui a variável infrax, por isso a variável foi excluída para a junção dos bancos.

PAN16 <-subset(Panama16, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))


PAN18 <-subset(Panama18, select=c("pais", "wt", "ur", "a4",
                                  "b1", "b2", "b3", "b4",
                                  "b6", "b13", "b18","b21",
                                  "b21a", "b32", "b37", "b47a",
                                  "ing4", "pn4", "vic1ext", "aoj11",
                                  "it1", "jc10", "q1",
                                  "q2", "ed", "q10new",
                                  "etid", "soct2", "idio2",
                                  "exc14", "cp8", "prot3", "vb2"))

PAR16 <-subset(Paraguai16, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))


PAR18 <-subset(Paraguai18, select=c("pais", "wt", "ur", "a4",
                                    "b1", "b2", "b3", "b4",
                                    "b6", "b13", "b18","b21",
                                    "b21a", "b32", "b37", "b47a",
                                    "ing4", "pn4", "vic1ext", "aoj11",
                                    "it1", "jc10", "q1",
                                    "q2", "ed", "q10new",
                                    "etid", "soct2", "idio2",
                                    "exc14", "cp8", "prot3", "vb2"))

PER16 <-subset(Peru16, select=c("pais", "wt", "ur", "a4",
                                "b1", "b2", "b3", "b4",
                                "b6", "b13", "b18","b21",
                                "b21a", "b32", "b37", "b47a",
                                "ing4", "pn4", "vic1ext", "aoj11",
                                "it1", "jc10", "q1",
                                "q2", "ed", "q10new",
                                "etid", "soct2", "idio2",
                                "exc14", "cp8", "prot3", "vb2"))


PER18 <-subset(Peru18, select=c("pais", "wt", "ur", "a4",
                                "b1", "b2", "b3", "b4",
                                "b6", "b13", "b18","b21",
                                "b21a", "b32", "b37", "b47a",
                                "ing4", "pn4", "vic1ext", "aoj11",
                                "it1", "jc10", "q1",
                                "q2", "ed", "q10new",
                                "etid", "soct2", "idio2",
                                "exc14", "cp8", "prot3", "vb2"))

REP16 <-subset(RepublicaDominicana16, select=c("pais", "wt", "ur", "a4",
                                               "b1", "b2", "b3", "b4",
                                               "b6", "b13", "b18","b21",
                                               "b21a", "b32", "b37", "b47a",
                                               "ing4", "pn4", "vic1ext", "aoj11",
                                               "it1", "jc10", "q1",
                                               "q2", "ed", "q10new",
                                               "etid", "soct2", "idio2",
                                               "exc14", "cp8", "prot3", "vb2"))


REP18 <-subset(RepublicaDominicana18, select=c("pais", "wt", "ur", "a4",
                                               "b1", "b2", "b3", "b4",
                                               "b6", "b13", "b18","b21",
                                               "b21a", "b32", "b37", "b47a",
                                               "ing4", "pn4", "vic1ext", "aoj11",
                                               "it1", "jc10", "q1",
                                               "q2", "ed", "q10new",
                                               "etid", "soct2", "idio2",
                                               "exc14", "cp8", "prot3", "vb2"))

URU16 <-subset(Uruguai16, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))


URU18 <-subset(Uruguai18, select=c("pais", "wt", "ur", "a4",
                                   "b1", "b2", "b3", "b4",
                                   "b6", "b13", "b18","b21",
                                   "b21a", "b32", "b37", "b47a",
                                   "ing4", "pn4", "vic1ext", "aoj11",
                                   "it1", "jc10", "q1",
                                   "q2", "ed", "q10new",
                                   "etid", "soct2", "idio2",
                                   "exc14", "cp8", "prot3", "vb2"))

### Criação da variável pais_recod para juntar os bancos de dados

ARG16$pais_recod <- recode(ARG16$pais, "17=1716")
ARG18$pais_recod <- recode(ARG18$pais, "17=1718")
BOL16$pais_recod <- recode(BOL16$pais, "10=1016")
BOL18$pais_recod <- recode(BOL18$pais, "10=1018")
BRA16$pais_recod <- recode(BRA16$pais, "15=1516")
BRA18$pais_recod <- recode(BRA18$pais, "15=1518")
CHI16$pais_recod <- recode(CHI16$pais, "13=1316")
CHI18$pais_recod <- recode(CHI18$pais, "13=1318")
COL16$pais_recod <- recode(COL16$pais, "8=816")
COL18$pais_recod <- recode(COL18$pais, "8=818")
COS16$pais_recod <- recode(COS16$pais, "6=616")
COS18$pais_recod <- recode(COS18$pais, "6=618")
ELS16$pais_recod <- recode(ELS16$pais, "3=316")
ELS18$pais_recod <- recode(ELS18$pais, "3=318")
EQU16$pais_recod <- recode(EQU16$pais, "9=916")
EQU18$pais_recod <- recode(EQU18$pais, "9=918")
GUA16$pais_recod <- recode(GUA16$pais, "2=216")
GUA18$pais_recod <- recode(GUA18$pais, "2=218")
HON16$pais_recod <- recode(HON16$pais, "4=416")
HON18$pais_recod <- recode(HON18$pais, "4=418")
MEX16$pais_recod <- recode(MEX16$pais, "1=116")
MEX18$pais_recod <- recode(MEX18$pais, "1=118")
NIC16$pais_recod <- recode(NIC16$pais, "5=516")
NIC18$pais_recod <- recode(NIC18$pais, "5=518")
PAN16$pais_recod <- recode(PAN16$pais, "7=716")
PAN18$pais_recod <- recode(PAN18$pais, "7=718")
PAR16$pais_recod <- recode(PAR16$pais, "12=1216")
PAR18$pais_recod <- recode(PAR18$pais, "12=1218")
PER16$pais_recod <- recode(PER16$pais, "11=1116")
PER18$pais_recod <- recode(PER18$pais, "11=1118")
REP16$pais_recod <- recode(REP16$pais, "21=2116")
REP18$pais_recod <- recode(REP18$pais, "21=2118")
URU16$pais_recod <- recode(URU16$pais, "14=1416")
URU18$pais_recod <- recode(URU18$pais, "14=1418")

# Junção dos bancos de dados de nível 1

AL <- rbind (ARG16, ARG18, BOL16, BOL18, BRA16, BRA18,
             CHI16, CHI18, COL16, COL18, COS16, COS18,
             ELS16, ELS18, EQU16, EQU18, GUA16, GUA18,
             HON16, HON18, MEX16, MEX18, NIC16, NIC18,
             PAN16, PAN18, PAR16, PAR18, PER16, PER18, 
             REP16, REP18, URU16, URU18)

# Alteração dos nomes das variáveis

AL$problema.pais <- AL$a4
AL$julga.justo <- AL$b1
AL$resp.inst <- AL$b2
AL$direitos <- AL$b3
AL$org.sist <- AL$b4
AL$apo.sist <- AL$b6
AL$conf.con <- AL$b13
AL$conf.pol <- AL$b18
AL$conf.part <- AL$b21
AL$conf.pres <- AL$b21a
AL$conf.muni <- AL$b32 
AL$conf.mid <- AL$b37
AL$conf.elei <- AL$b47a
AL$democracia <- AL$ing4
AL$satis.democ <- AL$pn4
AL$golpe.crime <- AL$jc10

AL$urbano <- AL$ur
AL$vitim <- AL$vic1ext
AL$sent.ins <- AL$aoj11
AL$sexo <- AL$q1
AL$idade <- AL$q2
AL$escola <- AL$ed
AL$conf.int <- AL$it1
AL$econ.pais <- AL$soct2
AL$econ.ind <- AL$idio2
AL$raça <- AL$etid
AL$rendaf <- AL$q10new

# Recodificação - Transformação de 1-7 para 1-10

AL$resp.inst01 <- AL$resp.inst/max(AL$resp.inst, na.rm = TRUE)
AL$resp.inst10 <- (AL$resp.inst01*10)
AL$julga.justo01 <- AL$julga.justo/max(AL$julga.justo, na.rm = TRUE)
AL$julga.justo10 <- (AL$julga.justo01*10)
AL$direitos01 <- AL$direitos/max(AL$direitos, na.rm = TRUE)
AL$direitos10 <- (AL$direitos01*10)
AL$org.sist01 <- AL$org.sist/max(AL$org.sist, na.rm = TRUE)
AL$org.sist10 <- (AL$org.sist01*10)
AL$apo.sist01 <- AL$apo.sist/max(AL$apo.sist, na.rm = TRUE)
AL$apo.sist10 <- (AL$apo.sist01*10)
AL$conf.con01 <- AL$conf.con/max(AL$conf.con, na.rm = TRUE)
AL$conf.con10 <- (AL$conf.con01*10)
AL$conf.pol01 <- AL$conf.pol/max(AL$conf.pol, na.rm = TRUE)
AL$conf.pol10 <- (AL$conf.pol01*10)
AL$conf.part01 <- AL$conf.part/max(AL$conf.part, na.rm = TRUE)
AL$conf.part10 <- (AL$conf.part01*10)
AL$conf.pres01 <- AL$conf.pres/max(AL$conf.pres, na.rm = TRUE)
AL$conf.pres10 <- (AL$conf.pres01*10)
AL$conf.muni01 <- AL$conf.muni/max(AL$conf.muni, na.rm = TRUE)
AL$conf.muni10 <- (AL$conf.muni01*10)
AL$conf.mid01 <- AL$conf.mid/max(AL$conf.mid, na.rm = TRUE)
AL$conf.mid10 <- (AL$conf.mid01*10)
AL$conf.elei01 <- AL$conf.elei/max(AL$conf.elei, na.rm = TRUE)
AL$conf.elei10 <- (AL$conf.elei01*10)
AL$democrac01 <- AL$democracia/max(AL$democracia, na.rm = TRUE)
AL$democrac10 <- (AL$democrac01*10)

AL$urbano <- recode(AL$urbano, "1=1; 2=0") # Urbano
table(AL$ur)
table(AL$urbano)
class(AL$urbano)

AL$vitim <- recode(AL$vitim, "1=1; 2=0") # Ser vítima
table(AL$vic1ext)
table(AL$vitim)
class(AL$vitim)

table(AL$sent.ins)
AL$sent.ins.dic <- recode(AL$sent.ins, "1:2=0 ; 3:4=1") # Inseguro
table(AL$aoj11)
table(AL$sent.ins.dic)

AL$sexo <- recode(AL$sexo, "1=0; 2=1") # Mulher
table(AL$q1)
table(AL$sexo)

AL$idfx <- cut(AL$idade, 
               breaks=c(0,30,40,50,60,120),
               labels=c("18-30 anos", 
                        "31-40 anos", 
                        "41-50 anos", 
                        "51-60 anos", 
                        "61 ou mais"))
table(AL$idfx)
AL$idfx <- as.numeric(AL$idfx)
class(AL$idfx)
table(AL$idfx)
table(AL$q2)

table(AL$etid)
AL$raça.dic <- recode(AL$raça, "2:1506=0; 1=1") # Ser branco
table(AL$raça.dic)

AL$escola.rec <- cut(AL$escola, c(0,14,18)) # 15 ou mais anos de escolaridade
table(AL$escola.rec)
class(AL$escola)

AL$conf.int.dic <- recode(AL$conf.int, "1:2=0; 3:4=1") #Desconfiança
table(AL$conf.int)
table(AL$conf.int.dic)
class(AL$conf.int.dic)

AL$econ.pais.dic <- recode(AL$econ.pais, "1:2=0; 3=1") #Pior
table(AL$econ.pais.dic)

AL$econ.ind.dic <- recode(AL$econ.ind, "1:2=0; 3=1") #Pior)

table(AL$econ.ind)
table(AL$econ.ind.dic)


AL$pais <- recode(AL$pais, "1='Mexico'; 2='Guatemala'; 3='El Salvador';
                 4='Honduras'; 5='Nicarágua'; 6= 'Costa Rica';
                 7='Panamá'; 8='Colômbia'; 9='Equador';
                 10='Bolívia'; 11='Peru'; 12='Paraguai';
                 13='Chile'; 14='Uruguai'; 15='Brasil';
                 17='Argentina'; 21='República Dominicana'")

save(AL, file="AL.RData") # BANCO NÍVEL 1

# Análise fatorial - construção de índices

BancoFatorial_2 <- subset(AL, select = c(resp.inst10, org.sist10,
                                         apo.sist10,
                                         direitos10, conf.con10,
                                         conf.part10, conf.pres10, 
                                         conf.elei10))

BancoNA_2 <- na.omit(BancoFatorial_2)
Fatorial_2 <- factanal(BancoNA_2, factors=2, rotation = "promax")
print(Fatorial_2)

Alpha_Cronbach_1 <- subset(AL, select = c(conf.con10, conf.part10,
                                          conf.elei10, conf.pres10))

Alpha_Cronbach_2 <- subset(AL, select = c(resp.inst10, org.sist10,
                                          apo.sist10, direitos10))


cronbach(Alpha_Cronbach_1) # Índice de confiança nas instituições
cronbach(Alpha_Cronbach_2) # Índice de apoio difuso


########### NÍVEL 2 #########################################################

# Junção dos bancos

Banco_Indicadores_AL <- read_excel("Banco_Indicadores_2016_2018 - AL.xlsx")

save(Banco_Indicadores_AL, file = "BI.RData")

Multi <- merge(AL, Banco_Indicadores_AL, by="pais_recod")

save(Multi, file = "Multi.RData")

Multi$IDH <- as.numeric(Multi$IDH)
Multi$Desemprego_jovens <- as.numeric(Multi$Desemprego_jovens)
Multi$Homicide <- as.numeric(Multi$Homicide)
Multi$Homicidio_MM <- as.numeric(Multi$Homicidio_MM)
Multi$Polity_IV <- as.numeric(Multi$Polity_IV)
Multi$V_Dem_Poliarquia <- as.numeric(Multi$v2x_polyarchy)
Multi$V_Dem_Liberal <- as.numeric(Multi$v2x_libdem)
Multi$V_Dem_Participacao <- as.numeric(Multi$v2x_partipdem)
Multi$Estabilidade_Politica <- as.numeric(Multi$Political_Stability)

############################# RESULTADOS ####################################
############################# RESULTADOS ####################################
############################# RESULTADOS ####################################
############################# RESULTADOS ####################################
############################# RESULTADOS ####################################

#############################################################################
############################# TABELA 1 ######################################
#############################################################################

# ÍNDICE DE CONFIANÇA NAS INSTITUIÇÕES

AL$Indiceconf <- AL$conf.con10 + AL$conf.part10 + AL$conf.elei10 + AL$conf.pres10
AL$Indiceconf01 <- AL$Indiceconf/max(AL$Indiceconf, na.rm = TRUE)
AL$Indiceconf10 <- (AL$Indiceconf01*10)

tapply(AL$Indiceconf10, AL$pais, summary) # Resultados índice de confiança nas instituições


# ÍNDICE DE APOIO DIFUSO

AL$Indiceapoiod <- AL$resp.inst10 + AL$org.sist10 + AL$apo.sist10 + AL$direitos10
AL$Indiceapoiod01 <- AL$Indiceapoiod/max(AL$Indiceapoiod, na.rm = TRUE)
AL$Indiceapoiod10 <- (AL$Indiceapoiod01*10)

tapply(AL$Indiceapoiod10, AL$pais, summary) # Resultados índice de apoio difuso

# ADESÃO À DEMOCRACIA

tapply(AL$democrac10, AL$pais, summary) # Resultados adesão a democracia

#############################################################################
############################# FIGURA 1 ######################################
#############################################################################

ModeloAL <- lm(Indiceconf10 ~ vitim + sent.ins.dic + sexo + 
                 idfx + escola.rec + conf.int.dic + econ.pais.dic +
                 econ.ind.dic, data=AL)

summary(ModeloAL)


confint(ModeloAL, level=.95)
figura1 <- coefplot(ModeloAL, innerCI=2, outerCI=0, intercept=FALSE)
figura1
ggsave("/Users/felipe/Desktop/dados_replicacao/figura1.png", 
       plot = figura1, width = 6, height = 4) # Figura 1

#############################################################################
############################# TABELA 2 ######################################
#############################################################################

# Informações nota de roda pé 28 - Modelo Nulo para o índice de confiança

Multi <- merge(AL, Banco_Indicadores_AL, by="pais_recod")

save(Multi, file = "Multi.RData")

Multi$IDH <- as.numeric(Multi$IDH)
Multi$Desemprego_jovens <- as.numeric(Multi$Desemprego_jovens)
Multi$Homicide <- as.numeric(Multi$Homicide)
Multi$Homicidio_MM <- as.numeric(Multi$Homicidio_MM)
Multi$Polity_IV <- as.numeric(Multi$Polity_IV)
Multi$V_Dem_Poliarquia <- as.numeric(Multi$v2x_polyarchy)
Multi$V_Dem_Liberal <- as.numeric(Multi$v2x_libdem)
Multi$V_Dem_Participacao <- as.numeric(Multi$v2x_partipdem)
Multi$Estabilidade_Politica <- as.numeric(Multi$Political_Stability)

MN_Apoioesp <- lme(Indiceconf10 ~ 1, random= ~ 1 | pais_recod, 
                   data= Multi, control= list(opt= "optmin"), na.action= na.omit) 
MN_Apoioesp
VarCorr(MN_Apoioesp)

# Índice de correlação intra-classe, 
# divisão do intercepto pelo somatório do intercepto mais o resíduo

0.3140763/(0.3140763 + 4.3718888)

# ICC= 6,7%, quanto maior a variabilidade entre os país, 
# maior a chance do impacto do efeito dos países

# Sem fazer variar por países

Nulo.apoioesp <- gls(Indiceconf10 ~1, data= Multi, 
                     control= list(opt= "optmin"), na.action= na.omit) 

Nulo.apoioesp
logLik(Nulo.apoioesp)*-2
logLik(MN_Apoioesp)*-2
225444.9-222202.7
anova(Nulo.apoioesp, MN_Apoioesp)

# Testar Hipóteses para Índice de Confiança nas Instituições

# Hipótese 1: Interação cross level entre vitimização e média móvel da taxa de homicídios; 
# Resultados hipótese 1 - Tabela 2

Model2.Apoioesp <- lme(Indiceconf10 ~ vitim + sent.ins.dic +
                         sexo +idfx + escola.rec + conf.int.dic + 
                         econ.pais.dic +
                         econ.ind.dic + Homicidio_MM + 
                         Homicidio_MM*vitim,
                       random = ~1|pais_recod, data = Multi, na.action=na.omit, 
                       control = list(opt="optim"))
summary(Model2.Apoioesp) # Resultados hipótese 1 - Interação entre vitimização e média móvel de homicídios - Tabela 2

# Hipótese 2: O efeito vitimização na legitimidade democrática é reduzido em contextos de maior estabilidade política e ausência de violência;

Model3.Apoioesp <- lme(Indiceconf10 ~ vitim + sent.ins.dic + sexo + 
                         idfx + escola.rec + conf.int.dic + econ.pais.dic +
                         econ.ind.dic + Estabilidade_Politica,
                       random = ~1|pais_recod, data = Multi,
                       na.action=na.omit, 
                       control = list(opt="optim"))
summary(Model3.Apoioesp) # Resultados hipótese 2 - Tabela 2

Model3.1Apoioesp <- lme(Indiceconf10 ~ vitim + sent.ins.dic + sexo + 
                          idfx + escola.rec + conf.int.dic + econ.pais.dic +
                          econ.ind.dic + Estabilidade_Politica +
                          Estabilidade_Politica*vitim,
                        random = ~1|pais_recod, data = Multi,
                        na.action=na.omit, 
                        control = list(opt="optim"))

summary(Model3.1Apoioesp) # Resultados hipótese 2 - com interação entre variáveis - Tabela 2

# Hipótese 3.1: Os efeitos da vitimização e do medo do crime na legitimidade democrática são mais acentuados em contextos de democracias menos consolidadas;

Model6.1Apoioesp <- lme(Indiceconf10 ~ vitim + sent.ins.dic + sexo + 
                          idfx + escola.rec + conf.int.dic + econ.pais.dic +
                          econ.ind.dic + V_Dem_Participacao +
                          V_Dem_Participacao*vitim,
                        random = ~1|pais_recod, data = Multi,
                        na.action=na.omit, 
                        control = list(opt="optim"))

summary(Model6.1Apoioesp) # Resultados hipótese 3.1 - com interação entre variáveis - Tabela 2

# Hipótese 3.2: Os efeitos da vitimização e do medo do crime na legitimidade democrática são mais acentuados em contextos de democracias menos consolidadas;

Model7.2Apoioesp <- lme(Indiceconf10 ~ vitim + sent.ins.dic + sexo + 
                          idfx + escola.rec + conf.int.dic + econ.pais.dic +
                          econ.ind.dic + V_Dem_Poliarquia +
                          V_Dem_Poliarquia*sent.ins.dic,
                        random = ~1|pais_recod, data = Multi,
                        na.action=na.omit, 
                        control = list(opt="optim"))

summary(Model7.2Apoioesp) # Resultados hipótese 3.2 - com interação entre variáveis - Tabela 2


#############################################################################
############################# GRÁFICO 1 ######################################
#############################################################################


# Interação entre vitimização e Média Móvel de Homicídios

TDAT.vitim_ae<-data.frame(vitim=c(0,0,1,1),
                          sent.ins.dic=c(0,0,0,0),
                          sexo=c(0,0,0,0),
                          idfx=c(1,1,1,1),
                          escola.rec=c(1,1,1,1),
                          conf.int.dic=c(0,0,0,0),
                          econ.pais.dic=c(0,0,0,0),
                          econ.ind.dic=c(0,0,0,0),
                          Homicidio_MM=c(9.69, 25.37, 9.69, 25.37))

predict(Model2.Apoioesp, TDAT.vitim_ae, level=0)

TDAT.vitim_ae$Indiceconf10<-predict(Model2.Apoioesp,TDAT.vitim_ae, level=0)
grafico1 <- with(TDAT.vitim_ae,interaction.plot(vitim,Homicidio_MM,Indiceconf10,
                                    legend=F,
                                    xlab="Vitimização",
                                    ylab="Índice de confiança nas instituições",
                                    main="Interação entre vitimização e taxa de homicídios"))
# Imagem gráfico 1 salva

grafico1 <- recordPlot()
png("/Users/felipe/Desktop/dados_replicacao/grafico1.png")
replayPlot(grafico1)
dev.off()


#############################################################################
############################# GRÁFICO 2 ######################################
#############################################################################


#Interação entre vitimização e com estabilidade política

TDAT.vitim_ae_es<-data.frame(vitim=c(0,0,1,1),
                             sent.ins.dic=c(0,0,0,0),
                             sexo=c(0,0,0,0),
                             idfx=c(1,1,1,1),
                             escola.rec=c(1,1,1,1),
                             conf.int.dic=c(0,0,0,0),
                             econ.pais.dic=c(0,0,0,0),
                             econ.ind.dic=c(0,0,0,0),
                             Estabilidade_Politica=c(30.48, 55.24, 30.48, 55.24))

predict(Model3.1Apoioesp, TDAT.vitim_ae_es, level=0)

summary(Multi$Estabilidade_Politica)

TDAT.vitim_ae_es$Indiceconf10<-predict(Model3.1Apoioesp,TDAT.vitim_ae_es, level=0)
grafico2 <- with(TDAT.vitim_ae_es,interaction.plot(vitim,Estabilidade_Politica,Indiceconf10,
                                       legend=F,
                                       xlab="Vitimização",
                                       ylab="Índice de confiança nas instituições",
                                       main="Interação entre vitimização e Estabilidade Política"))

# Imagem gráfico 2 salva

grafico2 <- recordPlot()
png("/Users/felipe/Desktop/dados_replicacao/grafico2.png")
replayPlot(grafico2)
dev.off()

#############################################################################
############################# APÊNDICE ######################################
#############################################################################

# TABELA 3

# Hipótese 1: Interação cross level entre vitimização e média móvel da taxa de homicídios; 

Model2.Apoiodif <- lme(Indiceapoiod10 ~ vitim + sent.ins.dic +
                         sexo +idfx + escola.rec + conf.int.dic + 
                         econ.pais.dic +
                         econ.ind.dic + Homicidio_MM + 
                         Homicidio_MM*vitim,
                       random = ~1|pais_recod, data = Multi,   na.action=na.omit, 
                       control = list(opt="optim"))

summary(Model2.Apoiodif) # Resultados hipótese 1 - Tabela 3

# Hipótese 2: O efeito vitimização na legitimidade democrática é reduzido em contextos de maior estabilidade política e ausência de violência;

Model3.Apoiodif <- lme(Indiceapoiod10 ~ vitim + sent.ins.dic + sexo + 
                         idfx + escola.rec + conf.int.dic + econ.pais.dic +
                         econ.ind.dic + Estabilidade_Politica,
                       random = ~1|pais_recod, data = Multi,
                       na.action=na.omit, 
                       control = list(opt="optim"))

summary(Model3.Apoiodif) # Resultados hipótese 2 - Tabela 3

# Hipótese 3.1: Os efeitos da vitimização e do medo do crime na legitimidade democrática são mais acentuados em contextos de democracias menos consolidadas;

Model6.1Apoiodif <- lme(Indiceapoiod10 ~ vitim + sent.ins.dic + sexo + 
                          idfx + escola.rec + conf.int.dic + econ.pais.dic +
                          econ.ind.dic + V_Dem_Participacao +
                          V_Dem_Participacao*vitim,
                        random = ~1|pais_recod, data = Multi,
                        na.action=na.omit, 
                        control = list(opt="optim"))

summary(Model6.1Apoiodif) # Resultados hipótese 3.1 - modelo com interação entre variáveis - Tabela 3

# Hipótese 3.2

Model7.1Apoiodif <- lme(Indiceapoiod10 ~ vitim + sent.ins.dic + sexo + 
                          idfx + escola.rec + conf.int.dic + econ.pais.dic +
                          econ.ind.dic + V_Dem_Poliarquia +
                          V_Dem_Poliarquia*vitim,
                        random = ~1|pais_recod, data = Multi,
                        na.action=na.omit, 
                        control = list(opt="optim"))

summary(Model7.1Apoiodif) # Resultados hipótese 3.2 - modelo com interação entre variáveis - Tabela 3

